package schoolWork.work04.test4;

public class BankAccount {
    private double balance;

    public BankAccount(double balance) {
        this.balance = balance;
    }

    public void deposit(double amount) throws NegativeAmountException {
        if (amount < 0)
            throw new NegativeAmountException("金额不能为负数:"+amount);
        balance += amount;
    }

    public void withdraw(double amount) throws NegativeAmountException, InsufficientFundsException {
        if(amount < 0)
            throw new NegativeAmountException("金额不能为负数:"+amount);
        else if(amount > balance)
            throw new InsufficientFundsException("余额不足,无法取出:"+amount);
        balance -= amount;
    }

    public double getBalance(){
        return balance;
    }
}